package work.timejay.shop.controller.sys;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import work.timejay.common.ApiResult;
import work.timejay.dto.shop.MenuAddDTO;
import work.timejay.dto.shop.MenuPageDTO;
import work.timejay.shop.service.sys.SysMenuService;
import work.timejay.vo.shop.MenuItemVO;

import java.util.List;

/**
 * <p>
 * 菜单权限表 前端控制器
 * </p>
 *
 * @author 王文杰
 * @since 2024-02-07
 */
@RestController
@RequestMapping("/api/sys-menu")
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    /**
     * 获取菜单列表
     */
    @PostMapping("/list")
    public ApiResult<List<MenuItemVO>> menuList(@RequestBody MenuPageDTO dto){
        List<MenuItemVO> voList = sysMenuService.menuList(dto);
        return ApiResult.success(voList);
    }

    /**
     * 添加菜单
     */
    @PostMapping(value = "/add")
    public ApiResult<Void> addMenu(@RequestBody @Validated MenuAddDTO dto){
        sysMenuService.addMenu(dto);
        return ApiResult.success();
    }

    /**
     * 修改菜单
     */
    @PostMapping(value = "/update")
    public ApiResult<Void> updateMenu(@RequestBody @Validated MenuAddDTO dto){
        sysMenuService.updateMenu(dto);
        return ApiResult.success();
    }

}

